home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Info / For Developers / PlayerPRO 5.2 Dev.Kit Mac / MADH Library 5.2 / MacOS Examples / Example.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-22  |  3.9 KB  |  160 lines  |  [TEXT/CWIE]

  1. /********************************************************/
  2. /*
  3.     Player PRO 5.0 -- Music Driver EXAMPLE
  4.  
  5.     Library Version 5.0
  6.  
  7.     To use with Think C & CodeWarrior
  8.  
  9.     Antoine ROSSET
  10.     16 Tranchees
  11.     1206 GENEVA
  12.     SWITZERLAND
  13.     
  14.     FAX: (+41 22) 346 11 97
  15.     PHONE: (+41 79) 203 74 62
  16.     Email: rossetantoine@bluewin.ch
  17. */
  18. /********************************************************/
  19.  
  20. #include "RDriver.h"            // Mad Driver functions & globals
  21.  
  22. /*****************************/
  23. /****** ERROR FUNCTION *******/
  24. /*****************************/
  25.  
  26. void MyDebugStr( short, Ptr, Ptr)
  27. {
  28. }
  29.  
  30.  
  31. void OSType2Ptr( OSType type, Ptr str)
  32. {
  33.     short i;
  34.     
  35.     BlockMoveData( &type, str, 4);
  36.     str[ 4] = 0;
  37. }
  38.  
  39. /*****************************/
  40. /****** MAIN FUNCTION ********/
  41. /*****************************/
  42.  
  43. void main( void)
  44. {
  45. Boolean                    End = false;
  46. MADDriverRec        *MADDriver;
  47. MADMusic                *MADMusic;
  48. MADLibrary            *MADLib;
  49.  
  50. /***************                    ****************/
  51. /******          Toolbox Initialization      **********/
  52. /***************                    ****************/
  53.  
  54. InitGraf( &qd.thePort);
  55. InitFonts();
  56. InitWindows();
  57. InitMenus();
  58. TEInit();
  59. InitDialogs(0L);
  60. InitCursor();
  61. MaxApplZone();
  62. MoreMasters();
  63.  
  64. /*******************************************************************************************/
  65. /****** MAD Library Initialisation : choose the best driver for the current hardware  ******/
  66. /******                                                                                  ******/
  67. /****** Standard initialization with 4 channels...                                      ******/
  68. /*******************************************************************************************/
  69.  
  70. {
  71. MADDriverSettings    init;
  72.  
  73.  
  74. /*
  75. MANUAL DRIVER CONFIGURATION, by example:
  76.  
  77. init.numChn                = 4;
  78. init.outPutBits         = 8;
  79. init.outPutRate            = rate22khz;
  80. init.outPutMode            = StereoOutPut;
  81. init.driverMode            = SoundManagerDriver;
  82. init.antiAliasing        = false;
  83. init.repeatMusic        = false;
  84. init.Interpolation        = false;
  85. init.MicroDelay            = false;
  86. init.MicroDelaySize     = 35;
  87. init.surround             = false;
  88. init.sysMemory            = false;
  89. init.Reverb                = false;
  90. init.ReverbSize            = 45;
  91. init.ReverbStrength        = 60;
  92. init.ReverbStrength        = 60;
  93. init.TickRemover        = false;
  94. */
  95.  
  96. /* or AUTOMATIC DRIVER CONFIGURATION FOR CURRENT MAC HARDWARE*/
  97. MADGetBestDriver( &init);
  98.  
  99. if( MADInitLibrary( "Plugs", init.sysMemory, &MADLib) != noErr) DebugStr("\pSmall Problem...");
  100. if( MADCreateDriver( &init, MADLib, &MADDriver) != noErr) DebugStr("\pSmall Problem...");
  101. }
  102. /*********************************/
  103. /*********************************/
  104. /*********************************/
  105.  
  106.  
  107. MADStartDriver( MADDriver);                // Turn interrupt driver function ON
  108.  
  109. /****** Open a music file via Plugs ********/
  110. while( End == false)
  111. {
  112.     StandardFileReply    reply;
  113.     SFTypeList            aType;
  114.     
  115.     FlushEvents( everyEvent, 0);
  116.     
  117.     StandardGetFile( 0L, -1, aType, &reply);
  118.     
  119.     
  120.     
  121.     if( !reply.sfGood) End = true;
  122.     else
  123.     {
  124.         char type[ 5];
  125.         
  126.         OSType2Ptr( reply.sfType, type);
  127.         
  128.         if( MADPlugAvailable( MADLib, type))        // Is available a plug to open this file?
  129.         {
  130.             if( MADLoadMusicFSpFile( MADLib, &MADMusic, type, &reply.sfFile) == noErr)        // Load this music with help of Plugs
  131.                                                                                                                                                                         // in application folder, in 'Plugs' folder or internal resources
  132.             {
  133.                 
  134.                 
  135.                 MADAttachDriverToMusic( MADDriver, MADMusic);
  136.                 MADPlayMusic( MADDriver);                    // Read the current partition in memory
  137.                 
  138.                 while( !Button())
  139.                 {
  140.                     /// Do what you want here....
  141.                     /// Bla bla...
  142.                     /// By example:    Run your realtime 3D game
  143.                     ///             with 24bit texture mapping...
  144.                     
  145.                     long    fT, cT;
  146.                     
  147.                     MADGetMusicStatus( MADDriver, &fT, &cT);    // Some infos about current music
  148.                 }
  149.                 MADStopMusic( MADDriver);                    // Stop reading current partition
  150.                 MADCleanDriver( MADDriver);
  151.                 MADDisposeMusic( &MADMusic, MADDriver);            // Dispose the current music
  152.             }
  153.         }
  154.     }
  155. }
  156. MADStopDriver( MADDriver);                // Stop driver interrupt function
  157. MADDisposeDriver( MADDriver);                        // Dispose music driver
  158. MADDisposeLibrary( MADLib);                    // Close music library
  159. FlushEvents( everyEvent, 0);            // Kill your events and byebye...
  160. }